package cn.tedu.supermarket.controller;

import cn.tedu.supermarket.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class CheckNameController {
    @Autowired
    private UserMapper userMapper;
    @RequestMapping(value = "/name", produces = "text/html;charset=utf-8")
    public String checkRegName(String username) {

        System.out.println("checkname开始");
        System.out.println(username);
        try  {
            int a = userMapper.selectBuyUserByName(username);
            if (a>0) {
                System.out.println("用户名已存在");
                return "用户名已存在";
            }else {
                System.out.println("用户名可用");
                return "用户名可用";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    @RequestMapping(value = "/LoginName", produces = "text/html;charset=utf-8")
    public String checkLoginName(String username) {
        System.out.println("checkLoginName开始");
        System.out.println(username);
        try  {
            int a = userMapper.selectBuyUserByName(username);
            if (a>0) {
                System.out.println("用户名存在");
                return "";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("用户名不存在");
        return "用户名不存在";
    }

    @RequestMapping(value = "/selUserName", produces = "text/html;charset=utf-8")
    public String suserName(String username) {

        System.out.println("checkname开始");
        System.out.println(username);
        try  {
            int a = userMapper.selectSelUserByName(username);
            if (a>0) {
                System.out.println("用户名已存在");
                return "用户名已存在";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("用户名可用");
        return "用户名可用";
    }

    @RequestMapping(value = "/LoginSelUserName", produces = "text/html;charset=utf-8")
    public String suserLoginName(String username) {
        System.out.println("checkLoginName开始");
        System.out.println(username);
        try  {
            int a = userMapper.selectSelUserByName(username);
            if (a>0) {
                System.out.println("用户名存在");
                return "";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("用户名不存在");
        return "用户名不存在";
    }
}


